package com.hk.employeemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hk.employeemanagementsystem.dto.AdvanceSearchEmpDto;
import com.hk.employeemanagementsystem.entity.EmployeeEntity;
import com.hk.employeemanagementsystem.mapper.EmployeeEntityMapper;
import com.hk.employeemanagementsystem.service.EmployeeEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author by 何坤
 * @Classname EmployeeEntityServiceImpl
 * @Description TODO
 * @Date 2019/12/19 15:17
 */
@Service
public class EmployeeEntityServiceImpl extends ServiceImpl<EmployeeEntityMapper, EmployeeEntity> implements EmployeeEntityService {

    @Resource
    private EmployeeEntityMapper employeeEntityMapper;

    @Override
    public List<EmployeeEntity> selectAllEmployee() {
        return employeeEntityMapper.selectAllEmployee();
    }

    @Override
    public Boolean validatorWorkIdUniqueness(String workId) {
        QueryWrapper<EmployeeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("emp_work_id", workId);
        EmployeeEntity employeeEntity = employeeEntityMapper.selectOne(wrapper);
        return employeeEntity == null ? false : true;
    }

    @Override
    public EmployeeEntity getEmployeeById(Integer id) {
        return employeeEntityMapper.getEmployeeById(id);
    }

    @Override
    public List<EmployeeEntity> selectEmployeeByWorkId(String workId) {
        return employeeEntityMapper.selectEmployeeByWorkId(workId);
    }

    @Override
    public Boolean validatorPhoneUniqueness(String phone, String workId) {
        QueryWrapper<EmployeeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("emp_phone", phone).ne("emp_work_id", workId == null ? "" : workId);
        EmployeeEntity employeeEntity = employeeEntityMapper.selectOne(wrapper);
        return employeeEntity == null ? false : true;
    }

    @Override
    public Boolean validatorEmailUniqueness(String email, String workId) {
        QueryWrapper<EmployeeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("emp_email", email).ne("emp_work_id", workId == null ? "" : workId);
        EmployeeEntity employeeEntity = employeeEntityMapper.selectOne(wrapper);
        return employeeEntity == null ? false : true;
    }

    @Override
    public Boolean validatorIdCardUniqueness(String idCard, String workId) {
        QueryWrapper<EmployeeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("emp_id_card", idCard).ne("emp_work_id", workId == null ? "" : workId);
        EmployeeEntity employeeEntity = employeeEntityMapper.selectOne(wrapper);
        return employeeEntity == null ? false : true;
    }

    @Override
    public List<EmployeeEntity> saveEmployee(EmployeeEntity employeeEntity) {
        employeeEntityMapper.insert(employeeEntity);
        return employeeEntityMapper.selectAllEmployee();
    }

    @Override
    public List<EmployeeEntity> advanceSearchEmp(AdvanceSearchEmpDto advanceSearchEmpDto) {
        return employeeEntityMapper.advanceSearchEmp(advanceSearchEmpDto);
    }
}
